package creatnews.controller;

import creatnews.service.AddTopicServicImpl;
import creatnews.service.IAddTopicService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 愿得一人心
 * @date 2022/2/25 11:12
 */
@WebServlet("/addTopic")
public class AddTopicController extends HttpServlet {
    private IAddTopicService iAddTopicService = new AddTopicServicImpl();
    private static final long serialVersionUID = 1L;


    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        String topicName = request.getParameter("topicName");
        //1、接收参数
        iAddTopicService.addTopic(topicName);


        //2、存储数据

        request.getRequestDispatcher("/news/topic/suc.jsp").forward(request,response);
    }


}
